/*
 * servos_motor.h
 *
 *  Created on: Apr 23, 2013
 *      Author: Daniel
 */

/* PWM2A	Servos 5-8 (Yaw Control)
 * PWM2B	Motor Control
 * PWM3A	Servo 1 (Pitch Control)
 * PWM3B	Servo 2 (Pitch Control)
 * PWM4A	Servo 3	(Roll Control)
 * PWM5A	Servo 4 (Roll Control)
 *
 * CMP values = (desired duty cycle)*600
 *
 */

#ifndef SERVOS_MOTOR_H_
#define SERVOS_MOTOR_H_


#define EPWM2345_TBPRD			59999	// period register for all other ePWMs

// PWM1: Clock divider
#define EPWM1_TBPRD				19		// period register for ePWM1
#define EPWM1_CMPA				1		// sets width of clock pulse (set no higher than 18)

// PWM2A: Servos 1-4 Control
#define EPWM2_CMPA_Min			2400	// 4% duty
#define EPWM2_CMPA_Default		4500	// 7.5% duty
#define EPWM2_CMPA_Max			6600	// 11% duty

// PWM2B: Motor Control
#define EPWM2_CMPB_Off			1		// ~0% duty, essentially motor off
#define EPWM2_CMPB_Low			3525	// 5.875% duty
#define EPWM2_CMPB_Hover		4400	// 7.45% duty (estimate)
#define EPWM2_CMPB_High			5718	// 9.53% duty

// PWM3A: Servo 5 Control
#define EPWM3_CMPA_Min			2238	// 3.73% duty
#define EPWM3_CMPA_Default		4578	// 7.63% duty
#define EPWM3_CMPA_Max			6918	// 11.53% duty

// PWM3B: Servo 6 Control
#define EPWM3_CMPB_Min			2100	// 3.50% duty
#define EPWM3_CMPB_Default		4200	// 7.00% duty
#define EPWM3_CMPB_Max			6732	// 11.22% duty

// PWM4A: Servo 7 Control
#define EPWM4_CMPA_Min			2316	// 3.86% duty
#define EPWM4_CMPA_Default		4464	// 7.44% duty
#define EPWM4_CMPA_Max			7038	// 11.73% duty

// PWM5A: Servo 8 Control
#define EPWM5_CMPA_Min			2220	// 3.70% duty
#define EPWM5_CMPA_Default		4638	// 7.73% duty
#define EPWM5_CMPA_Max			6942	// 11.57% duty

void InitPWM(void);
void InitPWM1(void);
void InitPWM2(void);
void InitPWM3(void);
void InitPWM4(void);
void InitPWM5(void);

#endif /* SERVOS_MOTOR_H_ */
